package com.sino.operation.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.entity.SysOrganization;
import com.sino.operation.service.impl.SysOrganizationServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Title: OrganizationController
 * @Description: 岗位管理
 * @Author dengls
 * @date 2021/10/12 15:22
 */
@Slf4j
@RestController
@RequestMapping("organizationManage")
@Api(value = "岗位管理", tags = "增加、修改、删除、查询")
public class OrganizationManageController {
    @Autowired
    private SysOrganizationServiceImpl sysOrganizationService;

    @GetMapping("/select")
    @ApiOperation(value = "查询岗位列表")
    @ResponseBody
    public IPage<SysOrganization> getObjects(@RequestParam Map<String, String> map) {
        return sysOrganizationService.selectList(map);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增岗位信息")
    @ResponseBody
    public CenterResponseEntity addObject(SysOrganization sysOrganization) {
        try {
            sysOrganizationService.saveOrUpdate(sysOrganization);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CenterResponseEntity.build();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "批量删除岗位信息")
    @ResponseBody
    public CenterResponseEntity deleteObject(List ids) {
        try {
            sysOrganizationService.removeByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改岗位信息")
    @ResponseBody
    public CenterResponseEntity updateObject(SysOrganization sysOrganization) {
        try {
            sysOrganizationService.saveOrUpdate(sysOrganization);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }
}
